package com.baizhi.controller;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.entity.CmfzLog;
import com.baizhi.service.CmfzLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("cmfzLog")
public class CmfzLogController {
    @Autowired
    private CmfzLogService cmfzLogService;
    private static Logger logger = LoggerFactory.getLogger(CmfzLogController.class);

    @RequestMapping("select")
    @LogAnnotation(content = "查询日志信息",type = "查询")
    public Map selectCmfzLog(Integer page,Integer limit,String logType){
        Map map = new HashMap();
        Page<CmfzLog> logPage = cmfzLogService.selectPage(page, limit, logType);
        map.put("code",0);
        map.put("msg","");
        map.put("count",logPage.getTotal());
        map.put("data",logPage.getRecords());
        logger.info("查询日志信息结果："+map);
        return map;
    }
    @RequestMapping("removeAny")
    @LogAnnotation(content = "批量删除日志信息",type = "删除")
    public Map removeAnyCmfzLog(Integer[] ids){
        logger.info("批量删除日志的参数："+ids);
        ArrayList<Integer> idsList = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            idsList.add(ids[i]);
        }
        Map map = new HashMap();
        try {
            cmfzLogService.deleteAnyCmfzLog(idsList);
            map.put("flag",true);
        } catch (Exception e) {
            map.put("flag",false);
            logger.error("批量删除日志报错");
        }
        return map;
    }
}
